grammar GramAntlr; 

options {
    output=AST; 
    ASTLabelType=CommonTree;
    }
 
tokens{
  INDICE;
  CONCAT;
  PARENTESIS;
  VACIO;
}

@header{
  package com.tleng; 
}

@lexer::header{
  package com.tleng;
}

x : e EOF!; 

e: a ('/'^ e)?;

a: b1=b(a1=a)?  -> {a1 != null}? ^(CONCAT $b1 $a1)
                -> b;

b: c1=c('^'c2=c)?('_'c3=c)? -> {c2 != null && c3 != null}? ^(INDICE $c1 $c2 $c3)
                            -> {c2 == null && c3 == null}? c
                            -> {c2 == null}? ^(INDICE $c1 VACIO $c3)
                            -> ^(INDICE $c1 $c2 VACIO); 

c: N | 
  '('e')' -> ^(PARENTESIS e) | 
  '{' e '}' -> e;

z : N EOF;

N :'0'..'9' | 'a'..'z' | 'A'..'Z' | '+' | '-' | '*';

ESP  
    :   (' ' | '\t' | '\r'| '\n') {$channel=HIDDEN;};